<?
	include("../includes/main_inc.php");
	if($_GET['id']) $confnum=$_GET['id'];
	if($_GET['SendEmail']){
		// --------------------------------Build info on sale
		$EmailBody="Thank you lalala etc..  \n Confirmation Number=$confnum \n\n Now for Reservation Details \n\n";
		
		$Total=0;
		$rslt=$r->RawQuery("SELECT id,propertyName,roomName,DATE_FORMAT(checkin,'%a %e %b %Y'),DATE_FORMAT(checkout,'%a %e %b %Y'),(price*amount),amount,DATEDIFF(checkin,checkout),bookingfee,membersID,guestName FROM bookings WHERE confnum='".$confnum."'");
		if($rslt){
			if(mysql_num_rows($rslt)>0){
				while($myrow=mysql_fetch_row($rslt)){
					$memberID=$myrow[9];
					$Total+=$myrow[5]+$myrow[8];
					$BFee+=$myrow[8];
					$EmailBody.="\n--------------------------------------------------------------\n";
					$EmailBody.="Guest Name=$myrow[10]\nProperty Name=$myrow[1]\n Room Name=$myrow[2]\n Checkin=$myrow[3]\n Checkout=$myrow[4]\n Number Of Rooms=$myrow[6]\n";
					$EmailBody.=" Number Of Nights=$myrow[7]\nSubTotal=AUD$ $myrow[5]\n ";
					$EmailBody.="\n--------------------------------------------------------------\n";
				}
				$EmailBody.="Booking Fee=AUD$ $BFee\n Total=AUD$ $Total";
				$EmailBody.="\n--------------------------------------------------------------\n";
			}
		}
		
		
		$rslt=$r->RawQuery("SELECT DISTINCT propertyID FROM bookings,weeklysale,room WHERE confnum='".$confnum."' AND bookings.weeklysaleID=weeklysale.id AND weeklysale.roomID=room.id");
		if($rslt){
			if(mysql_num_rows($rslt)>0){
				while($myrow=mysql_fetch_row($rslt)){
					$r->AddTable("property");
					$r->AddSearchVar($myrow[0]);
					$PInsert=$r->GetRecord();
					$EmailBody.="\n--------------------------------------------------------------\n";
					$EmailBody.="Property Name: $PInsert[propertyName]\n Check In / Check Out :$PInsert[checkIn] / $PInsert[checkOut]\n";
					$EmailBody.="Children & Extra Guests :$PInsert[extraGuests]\n Car Parking :$PInsert[carParking]\n";
					$EmailBody.="Location :$PInsert[location]\n Getting There : $PInsert[gettingThere]\n";
					$EmailBody.="Cancellation & Modification : Cancellation Policies Apply\n";
				};
			};
		};
		
		// -----------------------------------send to user
		include("../../classes/clsMail.php");
		
		// get member details for f/l name
		$r->AddTable("members");
		$r->AddSearchVar($memberID);
		$Insert=$r->GetRecord();
		
		$m=new SendMail();
		$m->To(array("$Insert[firstName] $Insert[lastName]"=>"$Insert[email]"));
		$m->Body(strip_tags($EmailBody),strip_tags($EmailBody),"");
		$m->From("ClickToGo","admin@click2go.com.au");
		$m->Subject("Reservation Details");
		$m->Send();
		
		$Message="Email Sent";
	}

?><html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Affiliate Bubble Administration</title>

<link href="<?=$rootdir?>css/admin.css" rel="stylesheet" type="text/css">
<script src="<?=$rootdir?>jscript/menuArray.js" language="javascript"></script>
<script src="<?=$rootdir?>jscript/clock.js" language="javascript"></script>
</head>

<body onLoad="funClock();">
<?php include("../includes/header.php"); ?>
<table width="100%" border="0" cellspacing="25" cellpadding="0">
<tr>
<td valign="top" width="240"><div id="menu"><?php include("../menu.php"); ?></div></td>
<td align="center" valign="top">

<div id="contentCompact">
<?=$Message;?>
<div id="title"> View Reservation - Confirmation Number - <?=$confnum;?>
</div>

<div id="contentLeft">
  <?
		  	$Total=0;
			$BTotal=0;
			$rslt=$r->RawQuery("SELECT id,propertyName,roomName,DATE_FORMAT(checkin,'%a %e %b %Y'),DATE_FORMAT(checkout,'%a %e %b %Y'),(price*amount),amount,DATEDIFF(checkin,checkout),guestName,bookingfee FROM bookings WHERE confnum='".$confnum."'");
		  	if($rslt){
				if(mysql_num_rows($rslt)>0){
					while($myrow=mysql_fetch_row($rslt)){
						$Total+=$myrow[5];
						$BTotal+=$myrow[9];
			  ?>
  <br>
  <table width="400" border="0" align="center" cellpadding="0" cellspacing="10">
    <tr>
      <td><strong>Guest's Name: </strong></td>
      <td><?=$myrow[8];?></td>
    </tr>
    <tr>
      <td><strong>Property:</strong></td>
      <td><strong>
        <?=$myrow[1];?>
      </strong></td>
    </tr>
    <tr>
      <td width="150"><strong>Room Type:</strong></td>
      <td><?=$myrow[2];?></td>
    </tr>
    <tr>
      <td><strong>Check In / Check Out: </strong></td>
      <td><?=$myrow[3];?>
        -
        <?=$myrow[4];?></td>
    </tr>
    <tr>
      <td><strong>Number Of Nights:</strong> </td>
      <td><?=$myrow[7];?>
        Nights </td>
    </tr>
    <tr>
      <td><strong>Number Of Rooms</strong></td>
      <td><?=$myrow[6];?></td>
    </tr>
    <tr>
      <td><strong>Price:</strong></td>
      <td>$
        <?=$myrow[5];?>
        AUD</td>
    </tr>
  </table>
  <?
					};
				};
			};
		   ?>
  <br>
  <br>
  <table width="400" border="0" align="center" cellpadding="0" cellspacing="10">
    <tr>
      <td width="150"><strong>Booking Fee (
        <?=($BookingFeeMultiplier*100);?>
        %) :</strong></td>
      <td>$<strong>
        <?=number_format($BTotal,2);?>
      </strong> AUD </td>
    </tr>
  </table>
  <p><br>
      <br>
  </p>
  <div id="paymentTotal"><span class="salePrice">Total: $<strong>
    <?=number_format($Total+$BTotal,2);?>
  </strong> AUD</span></div>
  <?
		  	$rslt=$r->RawQuery("SELECT DISTINCT propertyID FROM bookings,weeklysale,room WHERE confnum='".$confnum."' AND bookings.weeklysaleID=weeklysale.id AND weeklysale.roomID=room.id");
		  	if($rslt){
				if(mysql_num_rows($rslt)>0){
					while($myrow=mysql_fetch_row($rslt)){
						$r->AddTable("property");
						$r->AddSearchVar($myrow[0]);
						$Insert=$r->GetRecord();
			  ?>
  <table width="100%" border="0" cellspacing="10" cellpadding="0" id="conditions">
    <tr>
      <td><strong>Property Name</strong></td>
      <td><?=$Insert['propertyName'];?></td>
    </tr>
    <tr>
      <td width="26%"><strong>Check In<br>
        Check Out </strong></td>
      <td width="74%"><?=$Insert['checkIn'];?>
          <br>
          <?=$Insert['checkOut'];?></td>
    </tr>
    <tr>
      <td><strong>Children &amp; Extra Guests </strong></td>
      <td><?=$Insert['extraGuests'];?></td>
    </tr>
    <tr>
      <td><strong>Car Parking </strong></td>
      <td><?=$Insert['carParking'];?></td>
    </tr>
    <tr>
      <td><strong>Location</strong></td>
      <td><?=$Insert['location'];?></td>
    </tr>
    <tr>
      <td><strong>Getting There </strong></td>
      <td><?=$Insert['gettingThere'];?></td>
    </tr>
    <tr>
      <td class="redText"><strong>Cancellation &amp; Modification </strong></td>
      <td class="redText">Cancellation Policies Apply</td>
    </tr>
  </table>
  <?
					};
				};
			};
		   ?>
<p>&nbsp;</p>
  </div>

<div id="content"><a href="view-reservation.php?id=<?=$confnum;?>&SendEmail=1">Email Confirmation</a> &nbsp; <a href="#">Re Print Confirmation</a></div>
</div>

</td>
</tr>
</table>
</body>
</html>
